<%@page import="edu.gatech.team404.Course"%>
<%@page import="edu.gatech.team404.dal.CourseDAL"%>
<%@page import="edu.gatech.team404.tool.StatusCode"%>
<%@page import="java.util.ArrayList"%>

<%@include file="header.jsp" %>

<div id="content">
    <%@include file="sidebar.jsp" %>
    
    <div id="main">
    	<h1 align="center">Class Registration</h1>
    	
    	<div class="status">
			<%
				Object status = session.getAttribute("accountCreationStatus");
				if (status != null) {
					StatusCode code = (StatusCode) status;
					switch (code) {
						case REGISTER_SUCCESS :
							out.println("<p style=\"color:blue;\">");
							out.println("You have successfully registed for this class.");
							out.println("</p>");
						break;
						case REGISTER_FAIL :
							out.println("<p style=\"color:red;\">");
							out.println("Cannot register for this class. Please try again later.");
							out.println("</p>");
						break;
					}
				}
			%>
		</div>
    	
    	<div>
		    <form name="courseRegistration" action= "courseReg" method= "post">
				<table class="viewTable" border="0" cellpadding="10">
				<input type= "hidden" name="courseName" value='<%=request.getParameter("course") %>'>
					<tr>
						<th>Courses</th>
						<td>
				    		<select name="Courses" onChange="Script404.courseDesc(this.value, 'courseDescription')">
				    			<option value="">Select course</option>
								<% 
									CourseDAL cDal = new CourseDAL();
									ArrayList<Course> corses = (ArrayList<Course>) cDal.getAllCourses();
									cDal.close();
					    		
									for (Course corse : corses) {
						    			if (corse != null) {
											out.println("<option value=\"" + corse.getName() + "\">" + corse.getName() + "</option>");
						    			}
						    		}
					    		%>
							</select>
						</td>
					</tr>
					<tr>
						<td colspan=2>
							<input type= "hidden" name= "name" value='<%=getCookieByName(request.getCookies(), "username").getValue() %>'>
						</td>
					</tr>
					<tr>
						<td colspan=2 align""=left">
							<p id="courseDescription"></p>
						</td>
					</tr>
					<tr>
						<td colspan=2 align=center>
							<input type="submit" name="action" value="Register">
		          		</td>
					</tr>
				</table>
			</form>
		</div>
	</div>
</div>

<%@include file="footer.jsp"%>